package com.hongkuncheng.cms.model;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.io.Serializable;

@Entity
public class Article implements Serializable {
    protected int id;
    protected Integer checkflowId;
    protected String title;
    protected boolean bold;
    protected boolean red;
    protected String source;
    protected String author;
    protected String digest;
    protected String exturl;
    protected String contents;
    protected String contenttext;
    protected String image;
    protected Date publishtime;
    protected Date removetime;
    protected int clicknum;
    protected int sort;
    protected boolean protection;
    protected String protectionpassword;
    protected ArticleState articleState;
    protected Admin admin;
    protected Checknode checknode;
    private List<ArticleReColumns> articleReColumnses;
    protected List<Checkrecord> checkrecords;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "checkflow_id", nullable = true)
    public Integer getCheckflowId() {
        return checkflowId;
    }

    public void setCheckflowId(Integer checkflowId) {
        this.checkflowId = checkflowId;
    }

    @Basic
    @Column(name = "title", nullable = false, length = 255)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "bold", nullable = false)
    public boolean isBold() {
        return bold;
    }

    public void setBold(boolean bold) {
        this.bold = bold;
    }

    @Basic
    @Column(name = "red", nullable = false)
    public boolean isRed() {
        return red;
    }

    public void setRed(boolean red) {
        this.red = red;
    }

    @Basic
    @Column(name = "source", nullable = false, length = 255)
    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    @Basic
    @Column(name = "author", nullable = false, length = 255)
    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    @Basic
    @Column(name = "digest", nullable = true, length = 2000)
    public String getDigest() {
        return digest;
    }

    public void setDigest(String digest) {
        this.digest = digest == null || digest.isEmpty() ? null : digest;
    }

    @Basic
    @Column(name = "exturl", nullable = true, length = 255)
    public String getExturl() {
        return exturl;
    }

    public void setExturl(String exturl) {
        this.exturl = exturl == null || exturl.isEmpty() ? null : exturl;
    }

    @Basic
    @Column(name = "contents", nullable = true, length = -1)
    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        this.contents = contents == null || contents.isEmpty() ? null : contents;
    }

    @Basic
    @Column(name = "contenttext", nullable = true, length = -1)
    public String getContenttext() {
        return contenttext;
    }

    public void setContenttext(String contenttext) {
        this.contenttext = contenttext == null || contenttext.isEmpty() ? null : contenttext;
    }

    @Basic
    @Column(name = "image", nullable = true, length = 255)
    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image == null || image.isEmpty() ? null : image;
    }

    @Basic
    @Column(name = "publishtime", nullable = false)
    public Date getPublishtime() {
        return publishtime;
    }

    public void setPublishtime(Date publishtime) {
        this.publishtime = publishtime;
    }

    @Basic
    @Column(name = "removetime", nullable = true)
    public Date getRemovetime() {
        return removetime;
    }

    public void setRemovetime(Date removetime) {
        this.removetime = removetime;
    }

    @Basic
    @Column(name = "clicknum", nullable = false)
    public int getClicknum() {
        return clicknum;
    }

    public void setClicknum(int clicknum) {
        this.clicknum = clicknum;
    }

    @Basic
    @Column(name = "sort", nullable = false)
    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    @Basic
    @Column(name = "protection", nullable = false)
    public boolean isProtection() {
        return protection;
    }

    public void setProtection(boolean protection) {
        this.protection = protection;
    }

    @Basic
    @Column(name = "protectionpassword", nullable = true, length = 255)
    public String getProtectionpassword() {
        return protectionpassword;
    }

    public void setProtectionpassword(String protectionpassword) {
        this.protectionpassword = protectionpassword == null || protectionpassword.isEmpty() ? null : protectionpassword;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Article article = (Article) o;
        return id == article.id &&
                bold == article.bold &&
                red == article.red &&
                clicknum == article.clicknum &&
                sort == article.sort &&
                protection == article.protection &&
                Objects.equals(checkflowId, article.checkflowId) &&
                Objects.equals(title, article.title) &&
                Objects.equals(source, article.source) &&
                Objects.equals(author, article.author) &&
                Objects.equals(digest, article.digest) &&
                Objects.equals(exturl, article.exturl) &&
                Objects.equals(contents, article.contents) &&
                Objects.equals(contenttext, article.contenttext) &&
                Objects.equals(image, article.image) &&
                Objects.equals(publishtime, article.publishtime) &&
                Objects.equals(removetime, article.removetime) &&
                Objects.equals(protectionpassword, article.protectionpassword);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, checkflowId, title, bold, red, source, author, digest, exturl, contents, contenttext, image, publishtime, removetime, clicknum, sort, protection, protectionpassword);
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "state_id", referencedColumnName = "id", nullable = false)
    public ArticleState getArticleState() {
        return articleState;
    }

    public void setArticleState(ArticleState articleState) {
        this.articleState = articleState;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "admin_id", referencedColumnName = "id", nullable = false)
    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "checknode_id", referencedColumnName = "id")
    public Checknode getChecknode() {
        return checknode;
    }

    public void setChecknode(Checknode checknode) {
        this.checknode = checknode;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "article")
    public List<ArticleReColumns> getArticleReColumnses() {
        return articleReColumnses;
    }

    public void setArticleReColumnses(List<ArticleReColumns> articleReColumnses) {
        this.articleReColumnses = articleReColumnses;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "article")
    public List<Checkrecord> getCheckrecords() {
        return checkrecords;
    }

    public void setCheckrecords(List<Checkrecord> checkrecords) {
        this.checkrecords = checkrecords;
    }
}
